package cn.itlaobing.web.dao;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.regex.Pattern;

import cn.itlaobing.web.model.UserModel;

public class UserDao {
	private DBhelper db=new DBhelper();
	public UserModel QueryOne(String query,String pwd) throws SQLException,IOException{
		ResultSet rs=null;
		String sql="select * from tbl_user where counts=? or telephone=?";
		rs=db.executeQuery(sql,query,query);
		UserModel um=new UserModel();
		if(rs.next()) {
			um.setId(rs.getInt(1));
			um.setCounts(rs.getString("counts"));
			um.setLasttime(rs.getTimestamp("lasttime"));
			um.setNicheng(rs.getString("nicheng"));
			um.setPwd(rs.getString("pwd"));
			um.setTelephone(rs.getString("telephone"));
		}
		if(pwd.equals(um.getPwd())){
			String sql1="update tbl_user set lasttime=now() where id=?";
			db.executeUpdate(sql1,um.getId());
			return um;
		}
		return null;
	}
	public void close() throws SQLException{
		db.close();
	}
}
